import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
import 'package:safetymonitor/app/components/custom_refresh.dart';
import 'package:safetymonitor/app/core/http/http.dart';
import 'package:safetymonitor/app/core/utils/interface.dart';
import 'package:safetymonitor/app/data/entities/home/enterprise/enterprise_staff_entity_entity.dart';
import 'package:safetymonitor/modules/home/enterprise/a_enterprise_controller.dart';

///人员及证件照
class PeopleOrPapersController extends GetxController {
  /// 列表刷新key
  final GlobalKey<CustomEasyRefreshListState> globalKey = GlobalKey();

  //
  // Future<List<String>> getConnect(
  //     int pageIndex,
  //     int pageSize, {
  //       String? search, //搜索关键字
  //     }) async {
  //   final List<String> data = [
  //     'XXXXXX公司名称',
  //     'XXXXXX公司名称',
  //     'XXXXXX公司名称',
  //     'XXXXXX公司名称',
  //   ];
  //   return data;
  // }

  bool isNotPermissions=true;
  /// 获得人员及其证件照详情分页
  Future<List<EnterpriseStaffEntityEntity>> enterpriseStaffPage(int index, int size, {String? search}) async {
    final res = await HttpUtil().generateGetRequest<List<EnterpriseStaffEntityEntity>>(
      Interface.enterpriseStaffPage,
      queryParameters: {
        'pageNo': index,
        'pageSize': size,
        'companyName': Get.find<EnterpriseController>().selectCompany,
        'companyId': Get.find<EnterpriseController>().selectId,
        'staffName': null,
        'deptId':null,
        // 'total':0,
      },
    ).execute();
    List<EnterpriseStaffEntityEntity>? list = [];
    res.onSuccess((result) {
      if (result.data != null) {
        list = result.data;
      }
      isNotPermissions=true;
      update();
    });
    res.onError((result) {
      if(result.code==403&&result.message=='没有该操作权限'){
        isNotPermissions=false;
        update();
      }
    });
    return list??[];
  }
}
